<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Jedrzej\Pimpable\PimpableTrait;

class StorePink extends Model
{
    use HasFactory;
    use PimpableTrait;


    /**
     * 可搜索的字段
     */
    public $searchable = [
        'id',
        'status',
        'start_time',
        'stop_time',
    ];

    /**
     * 默认倒序
     */
    protected $defaultSortCriteria = ['id,asc'];

    /**
     * 状态枚举
     */
    public  $statusEnum = [
        'haveInHand' => '进行中',
        'completed' => '已完成',
        'noCompleted' => '未完成',
    ];

//    public  function storePink($data)
//    {
//        return $data->store_pink_count
//    }

    /**
     * 关联用户模型
     */

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id')->select('avatar','nickname','id');
    }

    /**
     * 关联订单模型
     */

    public function order()
    {
        return $this->belongsTo(Order::class, 'id', 'pink_id')->select('order_number');
    }

    /**
     * 关联拼团模型
     */

    public function storeCombination()
    {
        return $this->belongsTo( StoreCombination::class, 'combination_goods_id', 'id')->select('title','stop_at');
    }

    /**
     * 关联拼团模型
     */

    public function storePink()
    {
        return $this->hasMany( StorePink::class, 'head_id', 'id');
    }

}
